<!-- 立即还车页面点击还车后的页面returncar.php -->
<!DOCTYPE html>
<html>
<?php
// 开启会话
session_start();
// 引入数据库连接文件
require 'connection.php';
// 连接数据库
$conn = Connect();
?>

<head>
    <link rel="shortcut icon" type="image/png" href="assets/img/P.png.png">
    <link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="assets/css/customerlogin.css">
    <script type="text/javascript" src="assets/js/jquery.min.js"></script>
    <script type="text/javascript" src="assets/js/bootstrap.min.js"></script>
    <link rel="stylesheet" type="text/css" media="screen" href="assets/css/clientpage.css" />
</head>

<body id="page-top" data-spy="scroll" data-target=".navbar-fixed-top">
    <!-- 导航栏 -->
    <?php
    // 引入导航栏文件
    include './nav.php';
    ?>


    <?php
    // 自定义函数，用于计算日期差
    function dateDiff($start, $end)
    {
        $start_ts = strtotime($start);
        $end_ts = strtotime($end);
        $diff = $end_ts - $start_ts;
        return round($diff / 86400);
    }
    // 从 URL 获取 id 参数
    $id = $_GET["id"];
    // 查询租车信息
    $sql1 = "SELECT c.car_name, c.car_nameplate, rc.rent_start_date, rc.rent_end_date, rc.fare, rc.charge_type, d.driver_name, d.driver_phone
 FROM rentedcars rc, cars c, driver d
 WHERE id = '$id' AND c.car_id=rc.car_id AND d.driver_id = rc.driver_id";
    $result1 = $conn->query($sql1);
    if (mysqli_num_rows($result1) > 0) {
        while ($row = mysqli_fetch_assoc($result1)) {
            $car_name = $row["car_name"];
            $car_nameplate = $row["car_nameplate"];
            $driver_name = $row["driver_name"];
            $driver_phone = $row["driver_phone"];
            $rent_start_date = $row["rent_start_date"];
            $rent_end_date = $row["rent_end_date"];
            $fare = $row["fare"];
            $charge_type = $row["charge_type"];
            // 计算日期差
            $no_of_days = dateDiff("$rent_start_date", "$rent_end_date");
        }
    }
    ?>
    <div class="container" style="margin-top: 65px;">
        <div class="col-md-7" style="float: none; margin: 0 auto;">
            <div class="form-area">
                <form role="form" action="printbill.php?id=<?php echo $id ?>" method="POST">
                    <br style="clear: both">
                    <h3 style="margin-bottom: 5px; text-align: center; font-size: 30px;"> 旅程详情 </h3>
                    <h6 style="margin-bottom: 25px; text-align: center; font-size: 12px;"> 允许您的司机填写以下表单 </h6>

                    <h5> 车辆:&nbsp; <?php echo ($car_name); ?></h5>

                    <h5> 车辆号码:&nbsp; <?php echo ($car_nameplate); ?></h5>

                    <h5> 租车日期:&nbsp; <?php echo ($rent_start_date); ?></h5>

                    <h5> 结束日期:&nbsp; <?php echo ($rent_end_date); ?></h5>

                    <h5> 费用:&nbsp; Rs. <?php
                                        if ($charge_type == "days") {
                                            echo ($fare . "/天");
                                        } else {
                                            echo ($fare . "/公里");
                                        }
                                        ?>
                    </h5>

                    <h5> 司机姓名:&nbsp; <?php echo ($driver_name); ?></h5>

                    <h5> 司机联系方式:&nbsp; <?php echo ($driver_phone); ?></h5>
                    <?php if ($charge_type == "km") { ?>
                        <div class="form-group">
                            <input type="text" class="form-control" id="distance_or_days" name="distance_or_days" placeholder="输入行驶距离（公里）" required="" autofocus>
                        </div>
                    <?php } else { ?>
                        <h5> 天数：&nbsp; <?php echo ($no_of_days); ?></h5>
                        <input type="hidden" name="distance_or_days" value="<?php echo $no_of_days; ?>">
                    <?php } ?>
                    <input type="hidden" name="hid_fare" value="<?php echo $fare; ?>">

                    <input type="submit" name="submit" value="提交" class="btn btn-success pull-right">
                </form>
            </div>
        </div>
    </div>

</body>
<footer class="site-footer">
    <div class="container">
        <hr>
        <div class="row">
            <div class="col-sm-6">
                <h5>© <?php echo date("Y"); ?> Car Rentals</h5>
            </div>
        </div>
    </div>
</footer>

</html>